var u = navigator.appVersion;
var MLV = {
    downUrl_AN: 'http://zljy.wanaiyijia.cn:9786/',
    downUrl_IOS: 'https://testflight.apple.com/join/ojnKF127',
    qd: '',
    kfh: 0,
    uc: u.split('UCBrowser/').length > 1 ? 1 : 0,
    qq: u.split('MQQBrowser/').length > 1 ? 2 : 0,
    wx: ((u.match(/MicroMessenger/i)) && (u.match(/MicroMessenger/i).toString().toLowerCase() == 'micromessenger')),
    init: function () {
        this.kfh = this.getURLParameter('kfh') || 0;
        //获取渠道号
        this.qd = this.getURLParameter('qd') || 'meiju_1';
        this.downUrl_AN = this.downUrl_AN + this.qd + '/';
        // 禁止返回
        this.stopBack();
        // $(".lazy").lazyload({
        //     effect: "fadeIn",
        //     threshold: 200
        // });
        this.getBanners();
        this.getMoreVideos();
        this.bindEvent();
    },
    getBanners: function () {
        var _str = '';
        // $.each(bookData.bannerArry, function (i, o) {
        //     _str += '<div class="swiper-slide">';
        //     _str += '<img class="swiper-lazy" src="https://pic.rmb.bdstatic.com/bjh/5300a8d17bf2ea4a6c8f26e172d49653.jpeg" data-src="' + o.cover + '" alt="">';
        //     _str += '<div class="info">';
        //     _str += '<p>' + o.title + '</p><span>' + o.des + '</span>';
        //     _str += '</div></div>';
        // });
        $('#bannerCon').html(_str);
        new Swiper('#js_bigBanner', {
            loop: true,
            autoplay: {
                delay: 5000
            },
            lazy: {
                loadPrevNext: true,
            },
            pagination: {
                el: '.pager',
            },
        });
    },
    getMoreVideos: function () {
        var _str = '', _data = "";
        $.each(_data, function (i, o) {
            if (i < 15) {
                _str += '<li><div class="pic">';
                _str += '<img class="lazy" src="https://pic.rmb.bdstatic.com/bjh/732c164e61dc305a19736ff9381fe7ce.jpeg" data-original="' + o.cover + '" alt="">';
                _str += '</div><div class="info"><span>' + o.title + '</span></div>';
                _str += '</li>';
            }
        });
        $('#moreList').html(_str);
        // $(".lazy").lazyload({
        //     effect: "fadeIn",
        //     threshold: 200
        // });
    },
    sysTemInfo: function () {
        var us = navigator.userAgent.toLowerCase();
        if ((us.indexOf('android') > -1 || us.indexOf('linux') > -1) || navigator.platform.toLowerCase().indexOf('linux') != -1) {
            return 'android';
        } else if (us.indexOf('iphone') > -1 || us.indexOf('ipad') > -1) {
            return 'ios';
        }
    },
    getURLParameter: function (i) {
        return decodeURIComponent((new RegExp('[?|&]' + i + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
    },
    //浏览器禁止返回
    stopBack: function () {
        var that = this, _num = 0;
        if (window.history && window.history.pushState) {
            $(window).on('popstate', function () {
                _num++;
                if (Number(_num) <= that.kfh || that.kfh == 0) {
                    window.history.pushState('forward', null, document.URL);
                    window.history.forward(1);
                } else {
                    window.history.go(-1);
                }
            });
            window.history.pushState('forward', null, document.URL);
            window.history.forward(1);
        }
    },
    down: function () {
        if (this.sysTemInfo() == 'android') {
            if (this.wx) {
                $(".wechat").empty();
                $(".wechat").append('<img src="https://pic.rmb.bdstatic.com/bjh/a229e51cc71f6a4e18b24d20bcd52dcf.png" alt="点击右上角，然后选择浏览器打开！"/>');
                $(".wechat").show();
                return false;
            }
            // window.location.href=this.downUrl_AN;
        } else if (this.sysTemInfo() == 'ios') {
            if (this.wx) {
                $(".wechat").empty();
                $(".wechat").append('<img src="https://pic.rmb.bdstatic.com/bjh/84988cfaedc6c55e5efacc1ba10c462a.png" alt="点击右上角，然后选择浏览器打开！"/>');
                $(".wechat").show();
                return false;
            }
            // window.location.href=this.downUrl_IOS;
        }
    },
    bindEvent: function () {
        var _this = this;
        $(document).on('click', '.downApp', function () {
            _this.down();
        });
    }
}

$(function () {
    MLV.init();
})

Array.prototype.shuffle = function () {
    var input = this;
    for (var i = input.length - 1; i >= 0; i--) {
        var randomIndex = Math.floor(Math.random() * (i + 1));
        var itemAtIndex = input[randomIndex];
        input[randomIndex] = input[i];
        input[i] = itemAtIndex;
    }
    return input;
}